package util;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import core.Level;
/**
 * Load levels listed in a schema file
 * 
 * The level loader will take a schema file and instantiate the levels 
 * which are stored in it - separated by new lines - in an array list.
 * 
 * @author Alexander Schearer <aas11@duke.edu>
 *
 */
public class LevelLoader {
	
	public static List<Level> load(String schema) {
		List<Level> result = new ArrayList<Level>();
		try {
			Scanner reader = new Scanner(new File(schema));
			while (reader.hasNextLine()) {
				result.add((Level) Reflection.createInstance(reader.nextLine()));
			}
		} catch (Exception e) {
			return result;
		}
		return result;
	}
}
